# -*- coding: utf-8 -*-
import os
os.chdir("..")
import xpinyin as py

import csv

def convert_interest_features_2_pinyin(src_file,dist_file):
    p = py.Pinyin()

    f=open(src_file,'r')
    csv_f = csv.DictReader(f,fieldnames=['id','features','close_words'])

    items = []
    for i in csv_f:
        features = ' '.join([i['features'],i['close_words']])
        features = features.decode('utf-8')
        features = features.split(' ')
        features_pinyin=[]
        for ii in features:
            features_pinyin.append(p.get_pinyin(ii).encode('utf-8'))
        features_pinyin = ' '.join(features_pinyin)
        id_str = i['id']
        items.append({'id':id_str,'features':features_pinyin})

    f.close()

    f=open(dist_file,'w')
    csv_f = csv.DictWriter(f,fieldnames=['id','features'])
    csv_f.writerows(items)
    f.close()

if __name__ == '__main__':
    convert_interest_features_2_pinyin('../Data/dict/interest_features.csv','../Data/dict/interest_pinyin_features.csv')













#
